# -*- coding:utf-8 -*-
__author__ = 'lu'
import os

WORKSPACE_PATH = os.path.dirname(os.path.abspath(__file__))


def git_pull(repo_url, repo_path):
    repo = Gittle(repo_path, origin_uri=repo_url)
    #os.system('git pull')
    repo.pull()
    return repo.head


def git_switch_branch(repo_url, repo_path, branch):
    repo = Gittle(repo_path, origin_uri=repo_url)
    repo.checkout(repo._format_ref_branch('master'))
    git_pull(repo_url, repo_path)
    # repo.switch_branch(branch, create=False)
    repo.checkout(repo._format_ref_branch(branch))
    git_pull(repo_url, repo_path)
    return repo.head
